package com.jaymin.flink.datastream.transformation;

import org.apache.flink.api.common.functions.OpenContext;
import org.apache.flink.api.common.functions.RichMapFunction;

import java.math.BigDecimal;

/**
 * @author jaymin
 * @since 2024/4/5 19:05
 */
public class PkMapFunction extends RichMapFunction<String,Access> {
    /**
     * 业务逻辑操作
     * @param s
     * @return
     * @throws Exception
     */
    @Override
    public Access map(String s) throws Exception {
        System.out.println("----map----------");
        String[] splits = s.split(",");
        Long time = Long.parseLong(splits[0].trim());
        String domain = splits[1].trim();
        BigDecimal traffic = new BigDecimal(splits[2].trim());
        return new Access(time, domain, traffic);
    }

    /**
     * 初始化操作
     * @param openContext
     * @throws Exception
     */
    @Override
    public void open(OpenContext openContext) throws Exception {
        super.open(openContext);
        System.out.println("----open----------");
    }
}
